﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script>
    /*
      slice()
        有三个或多个参数时，替换元素
      语法：
        数组名.splice(start[, num, ele ...]);
          start ：第一个值为插入元素的位置
          num   ：第二个值为替换的个数。
          ele...：被替换的元素
    */
    let arr = [0, 1, 2, 3, 4, 5];

    // let arr2 = arr.splice(2, 2, "张飞", "牛肉", "手机", "鼠标");
    // console.log(arr, arr2);

    //如果第二个值为0，则不替换，直接插入6,7,8;

    let arr2 = arr.splice(2, 0, "张飞", "牛肉", "手机", "鼠标");
    console.log(arr, arr2);

    </script>
</body>
</html>